package com.sigmatrix.h5.web.controller.utils;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.sigmatrix.h5.entity.v2.Product;
import com.sigmatrix.h5.service.db.ProductDBService;
import com.sigmatrix.h5.web.BaseController;

/**
 * 通过product测试mybatic常用操作
 * 
 * @author wei.wang
 *
 */
@RestController
@RequestMapping("/util/test/product")
public class TestProductController extends BaseController {

	@Autowired
	private ProductDBService productDBService;

	//ok
	@GetMapping("/select/id/{id}/esecode/{esecode}")
	public Product selectById(HttpServletRequest request,@PathVariable Integer id,@PathVariable String esecode) {
		System.out.println(request.getRequestURI());
		System.out.println("====================");
		return productDBService.selectById(id, "_"+esecode);
	}
	
	//ok
	@PostMapping("/selectList/esecode/{esecode}")
	public List<Product> selectList(@PathVariable String esecode,@RequestBody Product product) {
		product.setTablePrefix("_"+esecode);
		return productDBService.selectList(new EntityWrapper<Product>(product));
	}
	
}
